package com.qidian.mes.defect.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.defect.mapper.IncomingMapper;
import com.qidian.mes.defect.service.IncomingService;
import com.qidianit.common.pojo.MESResult;
import com.qidianit.common.util.Constant;
import com.qidianit.mes.pojo.Defect;
import com.qidianit.mes.pojo.Incoming;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author 泽华
 * @Description
 * @Time 2024-10-22 14:37
 */
@Service
public class IncomingServiceImpl implements IncomingService {
    @Autowired
    private IncomingMapper incomingMapper;


    @Override
    public MESResult list(Incoming incoming, int page, int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Incoming> incomings = incomingMapper.selectList(incoming);
        PageInfo<Incoming> pageInfo = new PageInfo<>(incomings);
        // 将pageInfo对象设置到MESResult中
        return MESResult.success(pageInfo);

    }

    @Override
    public MESResult save(Incoming incoming) {
        return incomingMapper.insert(incoming) == 1?MESResult.success():MESResult.error();
    }

    @Override
    public MESResult update(Incoming incoming) {
        return MESResult.success(200,"ok",incomingMapper.update(incoming));
    }

    @Override
    public MESResult delete(Long incomingId) {
        Incoming incoming = new Incoming();
        incoming.setIncomingId(incomingId);
        incoming.setIncomingStatus(Constant.DATA_STATUS_DELETE);
        return MESResult.isSuccess(incomingMapper.deleteById(incoming));
    }

    @Override
    public MESResult selectById(Long incomingId) {
        return MESResult.success(incomingMapper.selectById(incomingId));

    }


}
